package com.mikasa.rabbitmq.quickstart;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class Procuder {

	
	public static void main(String[] args) throws Exception {

		// 1 创建一个ConnectionFactory, 并进行配置
		ConnectionFactory connectionFactory = new ConnectionFactory();
		connectionFactory.setHost("39.108.108.234");
		connectionFactory.setPort(5672);
		connectionFactory.setVirtualHost("/");
		
		// 2 通过连接工厂创建连接
		Connection connection = connectionFactory.newConnection();
		
		// 3 通过connection创建一个Channel
		Channel channel = connection.createChannel();
		
		// 4 通过Channel发送数据
		for(int i=0; i < 5; i++){
			String msg = "Hello RabbitMQ!";
			//1 exchange   2 routingKey
			// 正常发送消息必须指定 交换机 exchange ，如果没有指定则会走默认的（AMQP default)交换机，这个交换机的路由规则是安装 routingkey与队列的名字匹配
			channel.basicPublish("", "test001", null, msg.getBytes());
		}

		//5 记得要关闭相关的连接
		channel.close();
		connection.close();
	}
}
